package com.chuangketiebeta.ui;


import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.chuangketiebeta.BaseActivity;
import com.chuangketiebeta.MipcaActivityCapture;
import com.chuangketiebeta.R;
import com.chuangketiebeta.utils.CommonTools;
import com.chuangketiebeta.widgets.HomeSearchBarPopupWindow;
import com.chuangketiebeta.widgets.HomeSearchBarPopupWindow.onSearchBarItemClickListener;



public class IndexActivity extends BaseActivity implements OnClickListener, onSearchBarItemClickListener {
	private static final int SCANNIN_GREQUEST_CODE = 0;
	private ImageButton mCamerButton = null;
	private LinearLayout mTopLayout = null;
	private HomeSearchBarPopupWindow mBarPopupWindow = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_index);
		findViewById();
		initView();
	}
	@Override
	protected void findViewById() {
		// TODO Auto-generated method stub
		mCamerButton = (ImageButton) findViewById(R.id.index_camer_button);
		mCamerButton.setOnClickListener(this);
		mTopLayout = (LinearLayout) findViewById(R.id.index_top_layout);
	}

	

	@Override
	protected void initView() {
		// TODO Auto-generated method stub
		mBarPopupWindow = new HomeSearchBarPopupWindow(this,
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		mBarPopupWindow.setOnSearchBarItemClickListener(this);
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.index_camer_button:
			int height = mTopLayout.getHeight()
					+ CommonTools.getStatusBarHeight(this);
			mBarPopupWindow.showAtLocation(mTopLayout, Gravity.TOP, 0, height);
			mBarPopupWindow.setOnSearchBarItemClickListener(this);
			break;

		}
		
	}
	@Override
	public void onBarCodeButtonClick() {
		// TODO Auto-generated method stub
		Intent intent = new Intent();
		intent.setClass(this, MipcaActivityCapture.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivityForResult(intent, SCANNIN_GREQUEST_CODE);
		
	}
	@Override
	public void onCameraButtonClick() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onColorButtonClick() {
		// TODO Auto-generated method stub
		
	}

}
